import BackGround from './background'
import Ground from './ground'

export default class Main {
  constructor() {
    // 创建canvas
    canvas.width = SCREEN_WIDTH
    canvas.height = SCREEN_HEIGHT
    
    this.ctx = canvas.getContext('2d')
    
    this.bg = new BackGround()
    this.ground = new Ground() // 确保创建地面实例
    
    this.bindLoop = this.loop.bind(this)
    this.hasEventBind = false
    
    window.requestAnimationFrame(this.bindLoop)
  }

  render() {
    this.ctx.clearRect(0, 0, canvas.width, canvas.height)
    
    this.bg.render(this.ctx)
    this.ground.render(this.ctx) // 确保在背景之后渲染地面
  }

  update() {
    this.bg.update()
    this.ground.update() // 确保更新地面
  }

  loop() {
    this.update()
    this.render()
    
    window.requestAnimationFrame(this.bindLoop)
  }
} 